package fun.diaoer.common;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

import fun.diaoer.exception.AuthenException;
import fun.diaoer.exception.NullPointException;
import fun.diaoer.exception.GenericException;


/**
 * @author kevin
 *
 */

@RestControllerAdvice
public class GlobalExceptionHandler {
	
	
	@ExceptionHandler(AuthenException.class)
	@ResponseBody
    public JsonResult<String> handleAuthException(AuthenException e) {
		JsonResult<String> jr=new JsonResult<>();
		jr.setCode(500);
		jr.setStatus(false);
		jr.setMsg(String.format(" 认证失败:%s", e.getMessage()));
		return jr;
    }
	
	@ExceptionHandler(NullPointException.class)
	@ResponseBody
    public JsonResult<String> handleNullPointException(NullPointException e) {
		JsonResult<String> jr=new JsonResult<>();
		jr.setCode(500);
		jr.setStatus(false);
		jr.setMsg(String.format(" 空指针 :%s", e.getMessage()));
		return jr;
    }
	
	@ExceptionHandler(GenericException.class)
	@ResponseBody
    public JsonResult<String> handleMaxUploadSizeExceededException(GenericException e) {
		JsonResult<String> jr=new JsonResult<>();
		jr.setCode(500);
		jr.setStatus(false);
		jr.setMsg(String.format(" 其他错误:%s", e.getMessage()));
		return jr;
    }


}
